package com.luoshi.userservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.luoshi.entity.base.user.AclUser;
import com.luoshi.entity.base.user.vo.UserVo;
import com.luoshi.userservice.mapper.AclUserMapper;
import com.luoshi.userservice.service.AclUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;

/**
 * @ClassName AclUserServiceImpl
 * @Description:用户服务类实现
 * @Author luochangqin
 * @Date 2021/5/23
 * @Version V1.0
 **/
@Service
public class AclUserServiceImpl extends ServiceImpl<AclUserMapper, AclUser> implements AclUserService {
    /**
     * 带条件的分页查询
     * @param pageParam
     * @param queryVo
     * @return
     */
    @Override
    public IPage<AclUser> pageUserCondition(Page<AclUser> pageParam, UserVo queryVo) {


        // 多条件组合查询    mybatis学习过的动态sql
        String userName = queryVo.getUserName();
        String  nickName = queryVo.getNickName();
        Integer status = queryVo.getStatus();
        String beginTime = queryVo.getBeginTime();
        String endTime = queryVo.getEndTime();

        // 构建条件
        QueryWrapper<AclUser> wrapper = new QueryWrapper<>();

        // 判断条件值是否为空，如果为空不空拼接条件
        if(!StringUtils.isEmpty(userName)){
            wrapper.like("userName",userName);
        }
        if(!StringUtils.isEmpty(nickName)){
            wrapper.like("nick_name",nickName);
        }
        if(!StringUtils.isEmpty(status)){
            wrapper.eq("status",status);
        }
        if(!StringUtils.isEmpty(beginTime)){
            wrapper.ge("create_time",beginTime);
        }
        if (!StringUtils.isEmpty(endTime)) {
            wrapper.le("create_time",endTime);
        }
        //排序
        wrapper.orderByDesc("create_time");

        // 调用mapper的方法
        IPage<AclUser> pages = baseMapper.selectPage(pageParam, wrapper);
        return pages;
    }
}
